﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Spider.DataFactory;
using System.Data;

namespace Spider.Core
{
    public class DataEngin
    {
        List<Data> result = new List<Data>();

        IFactory name;

        IFactory content;

        IFactory width;

        IFactory height;

        IFactory face;

        IFactory age;

        IFactory job;

        IFactory educ;

        IFactory stance;

        IFactory QQ;

        IFactory city;


        public DataEngin()
        {
            name = new NameFactory();

            content = new ContentFactory();

            width = new WidthFactory();

            height = new HeightFactory();

            age = new AgeFactory();

            face = new FaceFactory();

            job = new JobFactory();

            educ = new EducationFactory();

            stance = new StanceFactory();

            QQ = new QQFactory();

            city = new CityFactory();

        }

        //public List<Data> Run()
        //{
        //    string query = "select * from qq where state=0";
        //    DataTable dt = SQLHelper.ExecuteDataset(query).Tables[0];

        //    foreach (DataRow row in dt.Rows)
        //    {
        //        Data data = new Data();
        //        data.Age = age.GetDate();
        //        data.Content = content.GetDate();
        //        data.Educ = educ.GetDate();
        //        data.Face = face.GetDate();
        //        data.Height = height.GetDate();
        //        data.Weight = width.GetDate();
        //        data.Job = job.GetDate();
        //        data.Name = name.GetDate();
        //        data.Stance = stance.GetDate();
        //        data.QQ = row["qq"].ToString();
        //        data.Sex = row["sex"].ToString();
        //        data.Province = row["city"].ToString();

        //        result.Add(data);
        //    }
        //    return result;
        //}


        public List<Data> Run()
        {
            string query = "select distinct name from name";
            DataTable dt = SQLHelper.ExecuteDataset(query).Tables[0];

            foreach (DataRow row in dt.Rows)
            {
                Data data = new Data();
                data.Age = age.GetDate();
                data.Content = content.GetDate();
                data.Educ = educ.GetDate();
                data.Face = face.GetDate();
                data.Height = height.GetDate();
                data.Weight = width.GetDate();
                data.Job = job.GetDate();
                data.Name = row["name"].ToString(); //name.GetDate();
                data.Stance = stance.GetDate();
                data.QQ = QQ.GetDate();
                data.Sex = "F";
                data.Province = city.GetDate();

                result.Add(data);
            }
            return result;
        }


        public int Save(List<Data> list)
        {
            foreach (Data item in list)
            {
                string insert = string.Format(
@"insert into detail(name,sex,age,height,weight,province,qq,content,state,face,job,education,stance,marriage)
values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}')",
item.Name, item.Sex, item.Age, item.Height, item.Weight, item.Province, item.QQ, item.Content, item.State, item.Face, item.Job, item.Educ, item.Stance, "单身");

                SQLHelper.ExecuteNonQuery(insert);
            }

            return 1;
        }



    }

    public class Data
    {
        public string Name { get; set; }
        public string Age { get; set; }
        public string Weight { get; set; }
        public string Height { get; set; }
        public string Face { get; set; }
        public string Educ { get; set; }
        public string Stance { get; set; }
        public string Job { get; set; }
        public string Content { get; set; }
        public string Sex { get; set; }
        public string Province { get; set; }
        public string QQ { get; set; }
        public string State { get { return "0"; } }
        public string Marriage { get { return "单身"; } }

    }
}
